package com.example.im.db.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.example.im.bean.ChatLast;

import java.util.List;

@Dao
public interface ChatLastDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    Long insert(ChatLast chatLast);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(List<ChatLast> chatLasts);

    @Update(onConflict = OnConflictStrategy.REPLACE)
    void update(ChatLast chatLast);

    @Delete
    void delete(ChatLast chatLast);

    @Query("DELETE FROM ChatLast WHERE u_id = :uid")
    void delete(int uid);

    @Query("SELECT * FROM ChatLast  ORDER BY t_id DESC")
    List<ChatLast> loadAll();

    @Query("SELECT * FROM ChatLast WHERE u_id = :uid")
    ChatLast selectChatLastsByUid(int uid);

    @Query("SELECT * FROM ChatLast WHERE t_id = :tid")
    ChatLast selectChatLastsByTid(int tid);


    @Query("UPDATE ChatLast SET is_ait= :isAit WHERE u_id = :uid")
    void upDateChatLastsByAit(boolean isAit, int uid);

}
